﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using ToDoClear;
using System.Collections.Generic;

namespace ToDoClear.HandleLogic
{
    public interface GestureHandle
    {
         MainState GetSupportState();

         void DragCompleted(object sender, DragCompletedGestureEventArgs e);

         void DragDelta(object sender, DragDeltaGestureEventArgs e);

         void DragStarted(object sender, DragStartedGestureEventArgs e);

         void Flick(object sender, FlickGestureEventArgs e);

         void GestureBegin(object sender, Microsoft.Phone.Controls.GestureEventArgs e);

         void GestureCompleted(object sender, Microsoft.Phone.Controls.GestureEventArgs e);

         void PinchCompleted(object sender, PinchGestureEventArgs e);

         void PinchDelta(object sender, PinchGestureEventArgs e);

         void PinchStarted(object sender, PinchStartedGestureEventArgs e);

         void Tap(object sender, Microsoft.Phone.Controls.GestureEventArgs e);

         void Hold(object sender, Microsoft.Phone.Controls.GestureEventArgs e);

    }
    public class HandleManager
    {
        private const string TAG = "HandleManager";
        private static HandleManager mHandleManager;
        public static HandleManager getInstance()
        {
            if (mHandleManager == null)
            {
                mHandleManager = new HandleManager();
                EnterState(MainState.IdleState);
                return mHandleManager;
            }
            return mHandleManager;
        }

        private List<GestureHandle> mList;
        EmptyHandle empty;
        private HandleManager()
        {
            mList = new List<GestureHandle>();
            mList.Add(new IdleHandle());
            mList.Add(new VerDragHandle());
            empty = new EmptyHandle();
        }

        public static GestureHandle currentHanlder;
        public static void EnterState(MainState state)
        {
            currentHanlder = null;
            for (int i = 0; i <getInstance(). mList.Count; i++)
            {
                if (getInstance().mList[i].GetSupportState() == state)
                {
                   currentHanlder = getInstance().mList[i];
                }
            }
            if (currentHanlder == null)
                currentHanlder = getInstance().empty;
            ToDoCanvas.getInstance().context.state=state;
            Log.d(TAG, "EnterState:" + state);
        }
        public static void EnterSubState(SubState state)
        {
            ToDoCanvas.getInstance().context.substate = state;
            Log.d(TAG, "EnterSubState:" + state);
        }
       
      
    }
}
